/**
 * lambda表达式的使用需要依赖与函数式接口
 * 函数式接口：只有一个抽象方法的接口
 */
@FunctionalInterface
interface hanshu {
    void text();

    //在函数式接口中，抽象方法只能有一个，但是其他方法可以存在
    default void hh() {
    }

    public static void hhh() {
    }
}

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

public class lambda {

    public static void main(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("no");
            }
        };
        noParameterNoReturn.test();


        NoParameterNoReturn noParameterNoReturn1 = ()->{System.out.println("no");};
        NoParameterNoReturn noParameterNoReturn2 = ()->System.out.println("no");
        noParameterNoReturn1.test();

        OneParameterNoReturn oneParameterNoReturn = (int a)->{System.out.println(a);};
        OneParameterNoReturn oneParameterNoReturn1 = (a) -> System.out.println(a);
        oneParameterNoReturn1.test(11);

        MoreParameterNoReturn moreParameterNoReturn = (int a,int b)->{System.out.println(a + b);};
        MoreParameterNoReturn moreParameterNoReturn1 = (a, b) -> System.out.println(a + b);
        moreParameterNoReturn1.test(1,3);

        NoParameterReturn noParameterReturn = ()->{return 1;};
        NoParameterReturn noParameterReturn1 = () -> 1;
        System.out.println(noParameterReturn.test());

        OneParameterReturn oneParameterReturn = (a)->{return a+2;};
        OneParameterReturn oneParameterReturn1 = a-> a+2;
        System.out.println(oneParameterReturn.test(2));

        MoreParameterReturn moreParameterReturn = (int a,int b)->{return a*b;};
        MoreParameterReturn moreParameterReturn1 = (a,b)->a*b;
        System.out.println(moreParameterReturn.test(2,10));
    }
}

